import { sys } from "cc";
import { RandomUtils } from "../../../Core/Utils/RandomUtils";
import SdkTool from "../../../Core/Sdk/SdkTool";
import { Enum } from "protobufjs";
import { ViewManager } from "../base/ViewManager";

export class ModelGameRobot {
    public static readonly myAtkTime = 20;
    public static readonly gridSize = 70;
    private static _state: number = 0;
    public static get state(): number {
        return ModelGameRobot._state;
    }
    public static set state(val: number) {
        ModelGameRobot._state = val;
    }
    private static _mesh: Object[][];
    public static mesh(): Object[][] {
        if (this._mesh) {
            return this._mesh;
        }
        this._mesh = [];
        for (let i = 0; i < 10; i++) {
            this._mesh[i] = [];
            for (let j = 0; j < 10; j++) {
                this._mesh[i][j] = { i: i, j: j, x: i * ModelGameRobot.gridSize, y: j * ModelGameRobot.gridSize };
            }
        }
        return this._mesh;
    }
    public static planeByrotate(rotate: number): any {
        switch (rotate) {
            case 0:
                return this.planeArray0;
            case 1:
                return this.planeArray2;
            case 2:
                return this.planeArray1;
            case 3:
                return this.planeArray3;
        }
    }
    public static randomthreeplane(): string {
        const plane1 = this.randomplane();
        const plane2 = this.randomplane();
        const plane3 = this.randomplane();
        if (this.findDuplicates(plane1[`temp`], plane2[`temp`], plane3[`temp`]).length > 0) {
            return this.randomthreeplane();
        } else {
            const str = `${plane1[`i`]}-${plane1[`j`]}+${plane1[`r`]}|${plane2[`i`]}-${plane2[`j`]}+${plane2[`r`]}|${plane3[`i`]}-${plane3[`j`]}+${plane3[`r`]}`;
            return str;
        }
    }
    private static randomplane(): {} {
        let dict: {} = {}
        const _i = RandomUtils.ins.limitInteger(0, 9);
        const _j = RandomUtils.ins.limitInteger(0, 9);
        const r = RandomUtils.ins.limitInteger(0, 3);
        const arr = ModelGameRobot.planeByrotate(r);
        let temp = []
        for (let i = 0; i < arr.length; i++) {
            const ii = arr[i].x + _i;
            const jj = arr[i].y + _j;
            temp.push(`${ii}-${jj}`);
        }
        dict[`i`] = _i;
        dict[`j`] = _j;
        dict[`r`] = r;
        dict[`temp`] = temp;
        return dict;
    }
    private static readonly planeArray0 = [
        { x: 2, y: 0 },
        { x: 0, y: 1 },
        { x: 1, y: 1 },
        { x: 2, y: 1 },
        { x: 3, y: 1 },
        { x: 4, y: 1 },
        { x: 2, y: 2 },
        { x: 1, y: 3 },
        { x: 2, y: 3 },
        { x: 3, y: 3 },
    ];
    private static readonly planeArray1 = [
        { x: 0, y: 2 },
        { x: 1, y: 0 },
        { x: 1, y: 1 },
        { x: 1, y: 2 },
        { x: 1, y: 3 },
        { x: 1, y: 4 },
        { x: 2, y: 2 },
        { x: 3, y: 1 },
        { x: 3, y: 2 },
        { x: 3, y: 3 },
    ];
    private static readonly planeArray2 = [
        { x: 2, y: 3 },
        { x: 0, y: 2 },
        { x: 1, y: 2 },
        { x: 2, y: 2 },
        { x: 3, y: 2 },
        { x: 4, y: 2 },
        { x: 2, y: 1 },
        { x: 1, y: 0 },
        { x: 2, y: 0 },
        { x: 3, y: 0 },
    ];
    private static readonly planeArray3 = [
        { x: 3, y: 2 },
        { x: 2, y: 4 },
        { x: 2, y: 3 },
        { x: 2, y: 2 },
        { x: 2, y: 1 },
        { x: 2, y: 0 },
        { x: 1, y: 2 },
        { x: 0, y: 3 },
        { x: 0, y: 2 },
        { x: 0, y: 1 },
    ];
    public static findDuplicates(arr1: string[], arr2: string[], arr3: string[]) {
        if (!arr1 || !arr2 || !arr3) {
            return [];
        }
        let rr = []
        let set = new Set();
        for (let i = 0; i < arr1.length; i++) {
            const iii = Number(arr1[i].split(`-`)[0])
            const jjj = Number(arr1[i].split(`-`)[1])
            if (iii > 9 || jjj > 9) {
                rr.push(arr1[i]);
                continue;
            }
            if (!set.has(arr1[i])) {
                set.add(arr1[i]);
            } else {
                rr.push(arr1[i]);
            }
        }
        for (let i = 0; i < arr2.length; i++) {
            const iii = Number(arr2[i].split(`-`)[0])
            const jjj = Number(arr2[i].split(`-`)[1])
            if (iii > 9 || jjj > 9) {
                rr.push(arr2[i]);
                continue;
            }
            if (!set.has(arr2[i])) {
                set.add(arr2[i]);
            } else {
                rr.push(arr2[i]);
            }
        }
        for (let i = 0; i < arr3.length; i++) {
            const iii = Number(arr3[i].split(`-`)[0])
            const jjj = Number(arr3[i].split(`-`)[1])
            if (iii > 9 || jjj > 9) {
                rr.push(arr3[i]);
                continue;
            }
            if (!set.has(arr3[i])) {
                set.add(arr3[i]);
            } else {
                rr.push(arr3[i]);
            }
        }
        return rr;
    }
    public static zeroPoint(param: number): number[] {
        switch (param) {
            case 0:
                return [-2, 0];
            case 1:
                return [-2, -3];
            case 2:
                return [0, -2];
            case 3:
                return [-3, -2];
        }
    }
}